package com.dragon.test.struts2.action;

import java.util.Arrays;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.HttpParameters;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 	获取表单数据
 * @author SmallDragon
 *
 */
public class GetFormAction extends ActionSupport {

	@Override
	public String execute() throws Exception {
		System.out.println("form in...");
		
		// ActionContext获取表单数据
		/*
		 * ActionContext context = ActionContext.getContext(); HttpParameters parameters
		 * = context.getParameters(); Set<String> keySet = parameters.keySet(); for
		 * (String key : keySet) { Object[] param = (Object[])
		 * parameters.get(key).getMultipleValues(); System.out.println(key + ":" +
		 * Arrays.toString(param)); }
		 */
		
		// ServletActionContext获取
		HttpServletRequest request = ServletActionContext.getRequest();
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String[] address = request.getParameterValues("address");
		System.out.println("username:" + username + ",password:" + password + ",address:" + Arrays.toString(address));
		
		request.setAttribute("reqValue", "request value");
		
		ActionContext context = ActionContext.getContext(); 
		context.getValueStack().set("setValue", "set value");
		
		
		return "hello";
	}
	

}
